package com.runner.suporte;

import android.R;
import android.app.Activity;
import android.widget.TextView;

public class MostrarExerciciosActivity extends Activity {
	private TextView ver_registro;
	private DataHelper dh;
	
	@Override
	public void onCreate(Bundle icicle){
		super.onCreate(icicle);
		setContentView(R.layout.mostrar_exercicios);
		dh = new DataHelper(this);
		findViewById(R.id.btElimina).setOnClickListern (new OnClickListener(){
			public void onClick(VIew v){
				eliminarUltimo();
			}
		});
		ver_registro = (TextView)findViewById(R.id.ver_registro);
		carregarDados();
	}
	public void onDestroy(){
		dh.close();
		super.onDestroy();
	}
	private void carregarDados(){
		List<Exercicio>exercicios = db.obterTodos();
		StringBuilder sb = new StringBuilder("");
		for (Exercicio exercicio: exercicios){
			sb.append(getString(R.string.mostrarExercicio, exercicio.getData(), exercicio.getTempo()));
		}
		this.ver_registro.setText(sb.toString());
	}
	private void eliminarUltimo(){
		dh.eliminarUltExercicio();
		carregarDados();
	}

}
